home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group02b.txt
/
000023_icon-group-sender_Tue Sep 10 07:49:26 2002.msg
< prev
next >
Wrap
Internet Message Format
|
2003-01-02
|
3KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id g8AEn4s10509
for icon-group-addresses; Tue, 10 Sep 2002 07:49:04 -0700 (MST)
Message-Id: <200209101449.g8AEn4s10509@baskerville.CS.Arizona.EDU>
X-Sender: whm@mail.mse.com
Date: Mon, 09 Sep 2002 23:03:24 -0700
To: Steve Graham <Steve_Graham@labcorp.com>
From: "William H. Mitchell" <whm@mse.com>
Subject: Re: Using Procedure Names for Debugging
Cc: Icon Group <icon-group@cs.arizona.edu>
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
At 12:35 PM 9/9/02 -0500, Steve Graham wrote:
>While developing an Icon program, I wanted an easy way to debug each
>procedure. I had read that there is more than 1 way to invoke a
>command. For example, you can have the statement write(5) or you can
>have "write"(5). I figured that I would use this idea to develop a test
>module, to which I would pass a procedure name and arguments. The test
>module would in turn invoke the specified procedure as in the 2nd
>example above with the arguments and report back the results, if any.
>However, I wasn't able to make it work. I'd bet there is a way,
>though. Any ideas?
That approach sounds fine but there may be some detail tripping you up.
One thing to note is that if you want to use string invocation (i.e.,
"x"(1)), you need an "invocable" declaration if you're going to invoke
non-builtins.
Here's a sample program that I think may do what you want:
invocable all # declares all procedures as invocable
procedure main(args)
if r := args[1]!args[2:0] then # calls procedure named as first
# command line argument with following
# command line arguments
write("Result: ", image(r))
else
write("Call failed...")
end
Here's a test procedure to use with it:
procedure x(y)
write("x called with ", y)
end
Here are some examples of usage, assuming it's named "rp" (run procedure):
$ rp center abc 20 .
Result: "........abc........."
$ rp find d "abcdefg"
Result: 4
$ rp find x "abcdefg"
Call failed...
$ rp x testing
x called with testing
Call failed...
Note that the last invocation, "rp x testing" fails because there's no
return or suspend at the end of x. Note also that without the "invocable
all" declaration, the last call would produce error 106.
Big picture-wise, however, you might find that qei, from the Icon Program
Library is a general purpose tool for interactively evaluating Icon
expressions:
$ qei
Icon Expression Evaluator, Version 1.2, type :? for help
> center("abc", 20, ".");
r1_ := "........abc........." (string)
> find("d", "abcdefg");
r2_ := 4 (integer)
> find("x", "abcdefg");
Failure
>